using Headspring.Training.Domain;
using Headspring.Training.Domain.Model;
using Headspring.Training.Domain.Services;
using StructureMap;

namespace Headspring.Training.Domain.Services.Impl
{
    [Pluggable(Keys.DEFAULT)]
    public class NotificationSender : INotificationSender
    {
        private IEmailSender _emailSender;
        private ISmsSender _smsSender;
    	private readonly IClock _clock;

    	public NotificationSender(IEmailSender emailSender, ISmsSender smsSender, IClock clock)
        {
            _emailSender = emailSender;
            _smsSender = smsSender;
        	_clock = clock;
        }
        public void Send(WorkOrderNotification notification)
        {
        	NotificationType notificationType =
        		notification.Recipient.GetNotificationTypeFor(_clock.GetCurrentTime().DayOfWeek);
        	if (notificationType == NotificationType.Email || notificationType == NotificationType.Both)
                _emailSender.Send(notification);
            if (notificationType == NotificationType.SMS || notificationType == NotificationType.Both)
                _smsSender.Send(notification);
        }
    }
}
